<?php if ($session->read('Auth.User.prefix') == CUST_PREFIX) : ?>
    <?php echo $this->element('displayHeader'); ?>
<?php endif; ?>
<div class="toolbar"><?php echo $this->element('toolbar', array('buttons' => array(array('refresh' => array('action' => 'stock_in_search'))))); ?></div>

<?php echo $form->create(null, array('controller' => 'cust_reports', 'action' => 'stock_in', 'target' => '_blank')); ?>
<fieldset>
    <legend>Criteria</legend>
    <table>
        <tr>
            <td width="120"><?php echo $form->label('CustProductSite.stock_code'); ?></td>
            <td width="250px"><?php echo $form->text('CustProductSite.stock_code'); ?></td>
            <td width="80px"><?php echo $form->label('Product.category_id', 'Category'); ?></td>
            <td><?php echo $form->select('Product.category_id', $categories, null, null, OPTION_ALL); ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('Product.brand_id', 'Brand'); ?></td>
            <td><?php echo $form->select('Product.brand_id', $brands, null, null, OPTION_ALL); ?></td>
            <td class="top"><?php echo $form->label('CustStockInHead.dispatch_from', 'Vendor'); ?></td>
            <?php if ($session->read('Auth.User.prefix') == SUPPLIER_PREFIX) : ?>
            <td colspan="2"><?php echo $form->hidden('CustStockInHead.dispatch_from', array('value' => SUPPLIER_PREFIX)); ?></td>
            <?php else : ?>
            <td><?php echo $form->radio('CustStockInHead.dispatch_from', array(ITS_PREFIX => 'ITS', SUPPLIER_PREFIX => 'Other Vendor', '' => 'All'), array('legend' => false)); ?></td>
            <?php endif; ?>
        </tr>
        <tr>
            <td colspan="4"><hr /></td>
        </tr>
        <tr>
            <td class="top"><?php echo $form->label('CustStockInHead.stock_in_date', 'Stock in Date'); ?></td>
            <td>
                From <?php echo $form->text('CustStockInHead.stock_in_date_start', array('size' => 7, 'class' => 'text-right')); ?>
                To <?php echo $form->text('CustStockInHead.stock_in_date_end', array('size' => 7, 'class' => 'text-right')); ?>
            </td>
            <?php if ($session->read('Auth.User.prefix') == SUPPLIER_PREFIX) : ?>
            <td colspan="2"><?php echo $form->hidden('CustStockInHead.supplier_id', array('value' => $session->read('Auth.User.supplier_id'))); ?></td>
            <?php else : ?>
            <td>&nbsp;</td>
            <td><?php echo $form->select('CustStockInHead.supplier_id', $suppliers, null, array('style' => 'display: none;'), OPTION_ALL); ?></td>
            <?php endif; ?>
        </tr>
        <tr>
            <td colspan="4"><hr /></td>
        </tr>
    </table>
<?php /*    <table>
        <tr>
            <td width="150px"><?php echo $form->label('Option.order1', 'Order by (1st Priority)'); ?></td>
            <td width="250px"><?php echo $form->select('Option.order1', $orderOptions, null, null, false); ?></td>
            <td width="80px"><label>Show as</label></td>
            <td ><?php echo $form->select('Option.seq', $seqOptions, null, null, false); ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('Option.order2', 'Order by (2nd Priority)'); ?></td>
            <td><?php echo $form->select('Option.order2', $orderOptions, null, null); ?></td>
            <td><label>Show Only</label></td>
            <td>
                <?php echo $form->text('Option.limit', array('size' => 5, 'class' => 'text-right')); ?> entries
                <span class="caption">(Leave blank for all.)</span>
            </td>
        </tr>
        <tr>
            <td colspan="4"><hr /></td>
        </tr>
    </table>*/?>
    <table>
        <tr>
            <td class="top" width="150px"><?php echo $form->label('display', 'Additional Information'); ?></td>
            <td>
                <?php echo $form->checkbox('Option.display_stock_in_no'); ?>&nbsp;&nbsp;Stock in no. / Stock in date / Product Description
            </td>
        </tr>
    </table>
    <?php echo $this->element('report/buttons', array('controller' => 'cust_reports', 'action' => 'stock_in', 'button' => array('search', 'print', 'excel'))); ?>
</fieldset>
<?php echo $form->end(); ?>

<script type="text/javascript">
    $j(function() {
        $j.datesearchpicker("#CustStockInHeadStockInDate");
        $j(':radio[id^=CustStockInHeadDispatchFrom]').bind('click', function() {
            var dispatch_from = $j(this).val();
            if (dispatch_from == SUPPLIER_PREFIX) {
                $j('#CustStockInHeadSupplierId').show();
                // ถ้าเลือก ITS หรือ All
            } else {
                $j('#CustStockInHeadSupplierId').hide().val('');
                // Request option ของ ITS กลับมาใส่ใหม่
                $j('#ProductBrandId').requestOptions('cust_product_sites/option_its_brand_list', null, {empty_option: '--All--'});
            }
        });

        // ติ๊ก dispatch from all ไว้ก่อน
        $j('#CustStockInHeadDispatchFrom').attr('checked', true);
        $j('button').handover();

        $j('#CustStockInHeadSupplierId').bind('change', function() {
            $j('#ProductBrandId').requestOptions('brands/option_list', $j(this).val(), {empty_option: '--All--'});
        });
    });
</script>


<?php echo $this->element('report/result'); ?>
